package com.auto.api.core.type.json.torna;

import cn.torna.sdk.param.DocParamResp;
import com.auto.api.common.utils.JsonMapper;
import com.auto.api.core.constants.MappingConstants;
import com.auto.api.core.util.BeanUtil;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ResolvableType;

/**
 * @program:
 * @description: TornaMapApiResultJsonTypeHandler类型处理器
 * @author: liangshf
 * @create: 2020-09-24
 */
public class TornaMapApiResultJsonTypeHandler extends AbstractTornaApiResultJsonTypeHandler {

    private static final Logger logger = LoggerFactory.getLogger(TornaMapApiResultJsonTypeHandler.class);

    @Override
    public boolean canCovert(ResolvableType resolvableType) {
        return resolvableType.resolve().getSimpleName().equals(MappingConstants.MAP);
    }

    @Override
    public String getResultJson(ResolvableType resolvableType, List<DocParamResp> responseParams){
        logger.warn("resultClass is error：{}", resolvableType.getType().getTypeName());
        DocParamResp data = BeanUtil.getDocResponseResp(MappingConstants.MAP, "", MappingConstants.MAP);
        data.setExample(MappingConstants.MAP);
        responseParams.add(data);
        return JsonMapper.toJson(responseParams);
    }
}